# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3"
pkgname=sircbot
pkgver=0.4
pkgrel=2
pkgdesc="Minimalistic IRC bot"
url="https://git.alpinelinux.org/cgit/sircbot/"
arch="all"
license="GPL-2.0"
pkgusers="sircbot"
pkggroups="sircbot"
depends=
makedepends=""
subpackages="lua-sircbot:luamod"
for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-sircbot:split_${_i/./_}"
done
install="$pkgname.pre-install"
source="https://dev.alpinelinux.org/archive/sircbot/sircbot-$pkgver.tar.xz
	0001-add-simple-hack-to-allow-nickserv-identification.patch
	sircbot.initd
	sircbot.confd
	"

builddir="$srcdir"/$pkgname-$pkgver

build() {
	cd "$builddir"
	make
	for i in $_luaversions; do
		make LUA_VERSION=$i
	done
}

package() {
	cd "$builddir"
	make install DESTDIR="$pkgdir" prefix=/usr
	for i in $_luaversions; do
		make install-lua DESTDIR="$pkgdir" prefix=/usr LUA_VERSION=$i
	done
	install -o sircbot -g sircbot -d "$pkgdir"/var/run/sircbot
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

luamod() {
	pkgdesc="sirbot client for Lua"
	mkdir -p "$subpkgdir"
}

_split() {
	local d= _ver=$1
	pkgdesc="Sircbot client for Lua $_ver"
	install_if="lua$_ver lua-sircbot=$pkgver-r$pkgrel"
	depends=
	cd "$pkgdir"
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}


for _v in $_luaversions; do
	eval "split_${_v/./_}() { _split $_v; }"
done

sha512sums="1f91581548dcc2d3f6d0da31591027792271994b86ffce73141de828eff27595a1df8a364988e0c5349996e36ae8879b166c84d6024a194626e61c9dc9e96816  sircbot-0.4.tar.xz
45cbf2b16374f0fb7746d80ce09a9f65c293e08fd641c174821caf78f27e0614882500e0ced08a611679f26e5b2f8acded9869af6be81bd0966820588612b1e6  0001-add-simple-hack-to-allow-nickserv-identification.patch
5a8ce80e8d43aa7737bd210812c8a99f1f5d5e7af78996b09ebef0c492d7df6303d63dbe3eb037fd5f750c955173e85fd87c75dfeb6dda7c731740d065ffa3d9  sircbot.initd
315167ec664ce859908fcd230f6e0c604a0b02e56286156ba6ec76c32d6d514726acb493fe7a13b44d9255ec2e34fe4b2a6f02edf039b06e487cea6528d4d6a7  sircbot.confd"
